<?php
/**
 * Created by PhpStorm.
 * User: woody
 * Date: 18-10-8
 * Time: 下午2:07
 */
namespace App\Http\Controllers\Api;

use App\Models\Vipusermarketapi;

use Config;
class VipusermarketController extends ApiController {

    public function __construct()
    {
        parent::__construct();
        $this->_response['_active']['_model']       = 'vipusermarket';
        $this->_response['_active']['_action']      = '';
        $this->_response['_title']                  = '小一农货-vip推广第二市场接口';

    }

    public function index(){

        $this->_response['_active']['_action']      = 'list';

        $vipusermarketModel = new Vipusermarketapi();

        $data = $vipusermarketModel->getData();
        if(!empty($data)){
            $this->_response['vipusermarket'] = $data;
            return response()->json(['code' => 0, 'msg' => '返回成功','data'=>$this->_response]);
        }else{
            return response()->json(['code' => -1, 'msg' => '返回失败']);
        }
    }

    public function doAdd(\App\Http\Requests\Vipusermarket $request){
        $data = $request->all();
        $saveData = [
            'user_id' => $data['user_id'],
            'vip_id'=>$data['vip_id'],
            'user_name' => $data['user_name'],
            'user_level' => $data['user_level'],
            'avatar'=>$data['avatar'],
            'created_at' => date('Y-m-d H:i:s', time()),
        ];

        $vipusermarketModel = new Vipusermarketapi();
        if($vipusermarketModel->saveData($saveData)){
            return response()->json(['code' => 0, 'msg' => '添加成功']);
        }else{
            return response()->json(['code' => -1, 'msg' => '添加失败']);
        }
    }



}